package com.kitty.record.kittyalgorithm.ds.queue;

import java.lang.reflect.Array;

/**
 * @author shenshen.qian@amh-group.com
 * @version 0.0.1
 * @date 2022/2/9 22:52
 */
public class MyArrayQueue<T> {

    private static final int DEFAULT_SIZE = 12;

    private T[] qt;


    private int qCount;


    public MyArrayQueue(Class<T> type, int size) {
        qt = (T[]) Array.newInstance(type, size);
        qCount = 0;
    }

    public MyArrayQueue(Class<T> type) {
        this(type, DEFAULT_SIZE);
    }


    /**
     * 将元素添加到队列尾部
     *
     * @param val
     */
    public void add(T val) {
        qt[qCount++] = val;
    }

    /**
     * 返回队列开头
     *
     * @return
     */
    public T front() {
        return qt[0];
    }

    /**
     * 返回队列开头并删除元素
     *
     * @return
     */
    public T pop() {
        T t = qt[0];
        qCount--;
        for (int i = 0; i < qCount; i++) {
            qt[i] = qt[i+1];
        }
        return t;
    }

    /**
     * 队列大小
     *
     * @return
     */
    public int size() {
        return qCount;
    }

    /**
     * 队列是否为空
     *
     * @return
     */
    public boolean isEmpty() {
        return qCount == 0;
    }


}
